package com.ruoyi.buss.grid.zysc.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.buss.grid.cj.domain.DataWgWgcj;
import com.ruoyi.buss.grid.cj.service.IDataWgWgcjService;
import com.ruoyi.buss.grid.zysc.domain.DataWgZysc;
import com.ruoyi.buss.grid.zysc.domain.DataWgZyscKh;
import com.ruoyi.buss.grid.zysc.domain.DataWgZyscSurvey;
import com.ruoyi.buss.grid.zysc.service.IDataWgZyscService;
import com.ruoyi.buss.utils.Params;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.system.api.model.LoginUser;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 网格专业市场Controller
 * 
 * @author ruoyi
 * @date 2021-09-26
 */
@RestController
@RequestMapping("/gridZysc")
public class DataWgZyscController extends BaseController
{
    @Autowired
    private TokenService tokenService;

    @Autowired
    private IDataWgZyscService dataWgZyscService;

    @Autowired
    private IDataWgWgcjService dataWgWgcjService;
    /**
     * 查询网格专业市场列表
     */
    @PreAuthorize(hasPermi = "buss:gridZysc:list")
    @GetMapping("/list")
    public TableDataInfo list(DataWgZysc dataWgZysc)
    {
        startPage();
        LoginUser userInfo = tokenService.getLoginUser();
        List<DataWgZysc> list = dataWgZyscService.selectDataWgZyscList(dataWgZysc,userInfo);
        return getDataTable(list);
    }

    /**
     * 查询网格专业市场列表
     */
    @PreAuthorize(hasPermi = "buss:gridZysc:queryGridZyscAll")
    @GetMapping("/queryGridZyscAll")
    public TableDataInfo queryGridZyscAll(DataWgZysc dataWgZysc)
    {
        LoginUser userInfo = tokenService.getLoginUser();
        List<DataWgZysc> list = dataWgZyscService.selectDataWgZyscList(dataWgZysc,userInfo);
        return getDataTable(list);
    }

    /**
     * 专业市场客户列表
     * @param dataWgZyscKh
     * @return
     */
    @PreAuthorize(hasPermi = "buss:gridZysc:queryGridZyscKhAll")
    @GetMapping("/queryGridZyscKhAll")
    public TableDataInfo queryGridZyscKhAll(DataWgZyscKh dataWgZyscKh){
        LoginUser userInfo = tokenService.getLoginUser();
        startPage();
        List<DataWgZyscKh> list = dataWgZyscService.queryGridZyscKhAll(dataWgZyscKh,userInfo);
        return getDataTable(list);
    }


    /**
     * 	专业市场业绩汇总列表
     */
    @PreAuthorize(hasPermi = "buss:gridZysc:queryGridZyscList")
    @GetMapping("/queryGridZyscList")
    public AjaxResult queryGridZyscList(DataWgZyscKh dataWgZyscKh)
    {
        String ifCheck = dataWgWgcjService.ifCheck(Params.IF_QUERY_GRIDZYSC_ALL);
        LoginUser userInfo = tokenService.getLoginUser();
        startPage();
        Map<String,Object> map = dataWgZyscService.queryGridZyscList(dataWgZyscKh, userInfo);
        map.put("qx",ifCheck);
        return AjaxResult.success(map);
    }


    @ApiOperation(value="APP网格年概况折线图")
    @GetMapping("/zyscAppBiYear")
    public TableDataInfo zyscAppBiYear()
    {
        LoginUser userInfo = tokenService.getLoginUser();

        startPage();
        List<DataWgZyscSurvey> list = dataWgZyscService.zyscAppBiYear(userInfo);
        return getDataTable(list);
    }

    @ApiOperation(value="APP网格季度概况折线图")
    @GetMapping("/zyscAppBiJd")
    public TableDataInfo zyscAppBiJd()
    {
        LoginUser userInfo = tokenService.getLoginUser();

        startPage();
        List<DataWgZyscSurvey> list = dataWgZyscService.zyscAppBiJd(userInfo);
        return getDataTable(list);
    }

    @ApiOperation(value="APP网格月度概况折线图")
    @GetMapping("/zyscAppBiMonth")
    public TableDataInfo zyscAppBiMonth()
    {
        LoginUser userInfo = tokenService.getLoginUser();

        startPage();
        List<DataWgZyscSurvey> list = dataWgZyscService.zyscAppBiMonth(userInfo);
        return getDataTable(list);
    }



    /**
     * 导出网格专业市场列表
     */
    @PreAuthorize(hasPermi = "buss:gridZysc:export")
    @Log(title = "网格专业市场", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataWgZysc dataWgZysc) throws IOException
    {
        LoginUser userInfo = tokenService.getLoginUser();
        List<DataWgZysc> list = dataWgZyscService.selectDataWgZyscList(dataWgZysc,userInfo);
        ExcelUtil<DataWgZysc> util = new ExcelUtil<DataWgZysc>(DataWgZysc.class);
        util.exportExcel(response, list, "网格专业市场数据");
    }

    /**
     * 获取网格专业市场详细信息
     */
    @PreAuthorize(hasPermi = "buss:gridZysc:query")
    @GetMapping(value = "/{marketId}")
    public AjaxResult getInfo(@PathVariable("marketId") String marketId)
    {
        return AjaxResult.success(dataWgZyscService.selectDataWgZyscById(marketId));
    }

    /**
     * 新增网格专业市场
     */
    @PreAuthorize(hasPermi = "buss:gridZysc:add")
    @Log(title = "网格专业市场", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataWgZysc dataWgZysc)
    {
        return toAjax(dataWgZyscService.insertDataWgZysc(dataWgZysc));
    }

    /**
     * 修改网格专业市场
     */
    @PreAuthorize(hasPermi = "buss:gridZysc:edit")
    @Log(title = "网格专业市场", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataWgZysc dataWgZysc)
    {
        return toAjax(dataWgZyscService.updateDataWgZysc(dataWgZysc));
    }

    /**
     * 删除网格专业市场
     */
    @PreAuthorize(hasPermi = "buss:gridZysc:remove")
    @Log(title = "网格专业市场", businessType = BusinessType.DELETE)
	@DeleteMapping("/{marketIds}")
    public AjaxResult remove(@PathVariable String[] marketIds)
    {
        return toAjax(dataWgZyscService.deleteDataWgZyscByIds(marketIds));
    }
}
